package com.whpost.service.zhdt.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whpost.service.entity.t.TreeNode;
import com.whpost.service.service.BaseServices;
import com.whpost.service.service.t.TApiNonceService;
import com.whpost.service.tools.ToolBean;
import com.whpost.service.zhdt.dao.ZhdtZbflMapper;
import com.whpost.service.zhdt.entity.ZhdtZbfl;
import com.whpost.service.zhdt.entity.ZhdtZbfl;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ZhdtZbflServices extends BaseServices<ZhdtZbflMapper, ZhdtZbfl> {

    @Resource
    private TApiNonceService tApiNonceService;


    public List<TreeNode> getTreeSelect(QueryWrapper<ZhdtZbfl> zhdtZbflQueryWrapper){
        List<ZhdtZbfl> allCpflList = baseMapper.selectList(zhdtZbflQueryWrapper);
        List<TreeNode> rootNodes = new ArrayList<>();

        // 1. 初始化所有节点，使用 value 而非 id
        for (ZhdtZbfl cpfl : allCpflList) {
            TreeNode node = new TreeNode();
            node.setValue(cpfl.getId());  // 将实体的 id 映射为节点的 value
            node.setName(cpfl.getName());
            node.setDisabled("0".equals(cpfl.getState()));
            node.setSelected(false);

            rootNodes.add(node);
        }
        return rootNodes;
    }
}
